package cn.dengta.webapp.trade.entity;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.context.model.LabelI18nProxy;
import cn.dengta.context.model.Option;
import cn.dengta.webapp.base.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.ArrayUtil;

@Setter
@Getter
@Accessors(chain = true)
@TableName("tr_form_template")
public class FormTemplate extends BaseEntity {

	/** 国家/语言 */
	private String country;
	/** 表单类型：0=绑定银行卡；1=绑定钱包； */
	private Integer formType;
	/** 表单key */
	private String name;
	/** 表单字段名称 */
	private String label;
	/** text|number|select */
	private String type;
	/** 是否必填: 0=否；1=是； */
	private Integer required;
	/** 字段描述 */
	private String placeholder;
	/** 下拉框参数 */
	@TableField(exist = false)
	private List<Option<Object>> select;

	@TableField(exist = false)
	private List<CashBank> options;
	/** 正则表达式 */
	private String regex;
	/** 错误提示 */
	private String errorMsg;
	/** 示例数据 */
	private String example;


	public enum AccType implements LabelI18nProxy<AccType, String> {
		/** main */
		C("C", "(C)Checking account", "US", "CO", "BR", "CL", "PE", "AR"),
		/** googleLite */
		P("P", "(P)Savings account", "US"),
		S("S", "(S)for Savings accounts ", "CO", "BR", "CL", "PE", "AR"),
		V("V", "(V)Vista account", "CL"),
		M("M", "(M)Maestra account", "PE"),
		;

		final ValueProxy<AccType, String> proxy;

		final String[] countries;


		AccType(String value, String label, String... countries) {
			this.countries = countries;
			proxy = new ValueProxy<>(this, value, label);
		}

		@Override
		public ValueProxy<AccType, String> getProxy() {
			return proxy;
		}

		public static AccType[] getValues() {

			return ValueProxy.getCachedArray(AccType.class, AccType::values);
		}

		public static AccType[] getValues(String country) {
			return Arrays.stream(ValueProxy.getCachedArray(AccType.class, AccType::values)).filter(d -> ArrayUtil.ins(country, d.countries)).toArray(AccType[]::new);
		}
	}

	public enum DocType implements LabelI18nProxy<DocType, String> {
		NIT("NIT", "NIT:纳税人识别号（Número de Identificación Tributaria/Tax Identification Number）", "CO"),
		/** googleLite */
		CC("CC", "CC:公民卡（cédula de ciudadanía/citizenship card）", "CO"),
		PASS("PASS", "PASS:护照 （passport）", "CO", "PE"),
		CE("CE", "CE:外国人身份证 (Cédula de Extranjería / Foreigners Identification Card) ", "CO","PE"),


		CPF("CPF", "CPF:个人税号 (Cadastro de Pessoas Físicas）", "BR"),
		CNPJ("CNPJ", "CNPJ:企业税号（Cadastro Nacional da Pessoa Juridica）", "BR"),

		RUT("RUT", "RUT:纳税人识别号(Rol Único Tributario/Tax Identification Number)", "CL"),


		DNI("DNI", "DNI:个人身份证（Documento Nacional de Identidad）", "PE"),
		RUC("RUC", "RUC:纳税人识别号（Registro Único de Contribuyentes/Tax Identification Number） ", "PE"),

		CUIT("CUIT", "CUIT:纳税人识别号(Clave Única de Identificación Tributaria(Laboral)", "AR"),
		CUIL("CUIL", "CUIL:纳税人识别号Tax Identification Number)", "AR"),
		;

		final ValueProxy<DocType, String> proxy;

		final String[] countries;

		DocType(String value, String label, String... countries) {
			this.countries = countries;
			proxy = new ValueProxy<>(this, value, label);
		}

		@Override
		public ValueProxy<DocType, String> getProxy() {
			return proxy;
		}

		public static DocType[] getValues() {
			return ValueProxy.getCachedArray(DocType.class, DocType::values);
		}

		public static DocType[] getValues(String country) {
			return Arrays.stream(ValueProxy.getCachedArray(DocType.class, DocType::values)).filter(d -> ArrayUtil.ins(country, d.countries)).toArray(DocType[]::new);
		}
	}

}
